﻿using System;
using UnityEngine;

namespace com.yoozoo.gta.Extension.UGUI.ScreenOrientationEx
{
    [Serializable]
    public class TransformAdaptConfig
    {
        public bool updateApply;
        public bool isActive;
        public Vector3 localPosition;
        public Vector3 localEulerAngles;
        public Vector3 localScale;
        
        //重写Equals方法
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return false;
            }

            TransformAdaptConfig other = (TransformAdaptConfig)obj;
            // Compare isActive properties
            if (updateApply != other.updateApply)
            {
                return false;
            }
            // Compare isActive properties
            if (isActive != other.isActive)
            {
                return false;
            }

            // Compare localPosition properties
            if (localPosition != other.localPosition)
            {
                return false;
            }
            
            // Compare localEulerAngles properties
            if (localEulerAngles != other.localEulerAngles)
            {
                return false;
            }
            
            // Compare localScale properties
            if (localScale != other.localScale)
            {
                return false;
            }

            return true;
        }
        
        //重写GetHashCode方法
        public override int GetHashCode()
        {
            int hash = 17;
            hash = hash * 23 + isActive.GetHashCode();
            hash = hash * 23 + localPosition.GetHashCode();
            hash = hash * 23 + localEulerAngles.GetHashCode();
            hash = hash * 23 + localScale.GetHashCode();
            return hash;
        }
    }
    [DisallowMultipleComponent]
    public class TransformAdapter: AdaptBase<TransformAdaptConfig,Transform>
    {
        protected override void ApplyConfig(TransformAdaptConfig config) {
            base.ApplyConfig(config);
            gameObject.SetActive(config.isActive);
            mComponent.localPosition = config.localPosition;
            mComponent.localEulerAngles = config.localEulerAngles;
            mComponent.localScale = config.localScale;
        }

        protected override void CopyProperty(TransformAdaptConfig config) {
            base.CopyProperty(config);
            config.isActive = gameObject.activeSelf;
            config.localPosition = mComponent.localPosition;
            config.localEulerAngles = mComponent.localEulerAngles;
            config.localScale = mComponent.localScale;
        }

        protected override void LateUpdate() {
            base.LateUpdate();
            if (CurrentConfig.updateApply) {
                ApplyConfig(CurrentConfig);
            }
        }
    }
}